package animix.blue.server.user.controller;

import animix.blue.server.common.bean.pojo.LogOperationAnno;
import animix.blue.server.common.bean.pojo.Result;
import animix.blue.server.common.bean.model.Role;
import animix.blue.server.user.service.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@Api(description = "角色管理API")
public class RoleController {

    @Autowired
    private RoleService roleService;

    @ApiOperation(value = "查询角色", notes = "根据条件查询，返回角色列表")
    @GetMapping("/role")
    public Result list(@RequestParam Map<String, Object> para) {
        return roleService.list(para);
    }

    @LogOperationAnno(action="新增", object="角色")
    @ApiOperation(value = "添加角色", notes = "根据Role对象创建角色")
    @PostMapping("/role")
    public Result add(@RequestBody Role role) {
        return roleService.add(role);
    }

    @LogOperationAnno(action="修改", object="角色")
    @ApiOperation(value = "修改角色", notes = "根据Role对象（Id）修改角色信息")
    @PutMapping("/role")
    public Result update(@RequestBody Role role) {
        return roleService.updateById(role);
    }
}
